#ifndef SDLDRAWING_H_INCLUDED
#define SDLDRAWING_H_INCLUDED

#include "common.h"
#include "matrixManagement.h"
#include "pixel.h"

#define SKULL_NO_DRAW 0
#define SKULL_ONLY 1
#define SKULL_OVERLAP 2

//! \brief Main drawing mode choice
enum MainDrawMode {OBJECT, ORIGINAL, HUE, SATURATION, VALUE};

//! \brief Drawing mode
typedef struct
{
    enum MainDrawMode mainMode;     //!< Main drawing mode
    char drawSkel;                  //!< Switch: Do we draw isobarycenters
    bool drawIsobar;                //!< Switch: Do we draw skeletons
} DrawMode;

//! \brief Drawing mode parameters
typedef struct
{
    Pixel** mat;                //!< Base color matrix
    PixelHSI** matHSI;          //!< Algorithm HSI matrix
    Taille sz;                  //!< Matrix sizes
    DrawMode drawMode;          //!< Drawing mode
} DrawParameters;

DrawParameters initDrawing(Pixel** baseMat, Taille sz);
void matriceAff(Pixel** mat, Taille size, SDL_Surface* screen, bool transparency = false, Pixel* transpPixel = NULL);
void maskAff(bool** mask, Taille size, SDL_Surface* screen, bool transparency);
void objAff(ObjectManager* objs, Taille size, SDL_Surface* screen);
void drawIsobar(ObjectManager* objs, SDL_Surface* screen);

//! \brief Converts a pixel into an SDL-type pixel
//!
//! \param px A pixel to convert
//! \param SDLpixel The pointer to the SDL-type pixel
//!
inline void setSDLPixelfromPixel (Pixel px, Uint8* SDLpixel) {SDLpixel[2] = px.r; SDLpixel[1] = px.g; SDLpixel[0] = px.b;}

void objCountAff(int count, SDL_Surface* screen);
void stateAff(const char* state, SDL_Surface* screen);
void textAff(const char* text, SDL_Rect pos, SDL_Surface* screen);

Pixel Hvalue(PixelHSI px);
Pixel Svalue(PixelHSI px);
Pixel Ivalue(PixelHSI px);

void drawScene(SDL_Surface* screen, ObjectManager* objs, DrawParameters drawParams);

void saveResult(SDL_Surface* screen, int, int);

//! \brief
//!
//! \param mat A matrix to convert and print
//! \param size The size of mat
//! \param fun A converting function
//! \param screen A surface to draw the converted matrix onto
//!
//!
template<typename T> void matrixValue (T** mat, Taille size, Pixel(*fun)(T), SDL_Surface* screen)
{
    Pixel fill = {0,0,0};
    Pixel** pxMatrix = createMatrix(size, fill);
    applyMatrix(mat, pxMatrix, size, fun);
    matriceAff(pxMatrix ,size, screen);
    freeMatrix(pxMatrix, size);
}

#endif // SDLDRAWING_H_INCLUDED
